<!--
 * @Descripttion:
 * @version:
 * @Author: sueRimn
 * @Date: 2020-11-14 14:16:34
 * @LastEditors: sueRimn
 * @LastEditTime: 2020-11-14 16:24:44
-->
<template>
  <div class="app-container">
    <!-- //查询条件 -->
    <div class="search">
      <div class="search_left">
        <el-form :inline="true" :model="searchForm" class="demo-form-inline">
          <el-form-item label="条件一">
            <el-input v-model="searchForm.roles1" placeholder="教师姓名" />
          </el-form-item>
          <el-form-item label="条件二">
            <el-input v-model="searchForm.roles2" type="tel" placeholder="联系方式" />
          </el-form-item>
        </el-form>
      </div>
      <div class="search_right">
        <el-button type="primary" @click="get_ListData">查询</el-button>
        <el-button type="info" @click="reset">重置</el-button>
      </div>
    </div>
    <!-- 操作条件 -->
    <div class="btnGround">
      <div>
        <el-button type="primary">新增机构</el-button>
        <el-button type="danger">批量删除</el-button>
      </div>
    </div>
    <!-- 表格 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
      @selection-change="handleSelectionChange"
    >
      <!-- //多选选项 -->
      <el-table-column
        type="selection"
        width="55"
      />
      <el-table-column
        width="50"
        label="序号"
        align="center"
      >
        <template slot-scope="scope">
          {{ scope.$index + 1 + pageSize*(currentPage - 1 ) }}
        </template>
      </el-table-column>
      <el-table-column label="姓名" align="center">
        <template slot-scope="scope">
          {{ scope.row.name }}
        </template>
      </el-table-column>
      <el-table-column label="联系方式" width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.phone }}</span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        width="120"
        align="center"
      >
        <template>
          <el-button size="mini" type="success">操作</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- //分页 -->
    <div class="bottomPagination">
      <el-pagination
        :current-page="currentPage"
        :page-sizes="[10,30,50]"
        :page-size="pageSize"
        layout=" sizes, prev, pager, next,total, jumper"
        :total="total"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
      />
    </div>
  </div>
</template>

<script>
export default {
    name: 'TrembleSchool',
    data() {
        return {
            // 属性命名要与查询属性一致
            searchForm: {
                roles1: '',
                roles2: ''
            },
            list: [{
                name: 'name',
                phone: 'phone'
            }], // 表格数据
            currentPage: 1, // 页数
            total: 0, // 总数
            pageSize: 10, // 每页条数
            listLoading: false, // table 加载
            multipleSelection: [] // 多选
        }
    },
    created() {
        // 初始化表格
        // this.get_ListData()
    },
    methods: {
        // 获取列表数据
        async get_ListData() {
            this.listLoading = true
            var queryData = {
                limit: this.pageSize,
                page: this.currentPage
            }
            var searchObj = this.searchForm
            // 自动添加查询条件
            for (let key in searchObj) {
                if (searchObj[key]) {
                    queryData[key] = searchObj[key]
                }
            }
            var data = await REQUEST_API(queryData)
            if (data.code == 200) {
                this.list = data.data
                this.total = data.total
            }
            this.listLoading = false
        },
        // 条件重置
        reset() {
            // 属性命名要与查询属性一致
            this.searchForm = {
                roles1: '',
                roles2: ''
            }
            this.currentPage = 1
            this.get_ListData()
        },
        handleSelectionChange(val) {
            this.multipleSelection = val
            console.log(this.multipleSelection)
        },
        handleCurrentChange(val) {
            this.currentPage = val
            this.get_ListData()
        },
        handleSizeChange(val) {
            this.currentPage = 1
            this.pageSize = val
            this.get_ListData()
        }
    }
}
</script>

<style scoped lang='scss'>
.search{
    display: flex;
    justify-content:space-between;
    align-items: center;
    flex-wrap: wrap;
    width: 100%;
    .search_left{
        display: flex;
        align-items: center;
        .el-form-item{
            margin-bottom: 0 !important;
        }
    }
    .search_right{}
}

.btnGround {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    flex-direction: row-reverse;
    justify-content: space-between;
    margin: 20px 0 15px 0;
}

.bottomPagination {
    padding: 15px 0;
}
</style>
